package com.itheima.Entry;

import com.itheima.bean.*;
import com.itheima.mapper.OnetoOneZj;
import com.itheima.service.ClasestoStudent_Service;
import com.itheima.service.Double_Service;
import com.itheima.service.StudentService;
import com.itheima.service.TeachertoStudent_Service;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Test {
    private StudentService studentService = new StudentService();
    private Double_Service double_service=new Double_Service();
    private ClasestoStudent_Service clasestoStudent_service=new ClasestoStudent_Service();
    @org.junit.Test
    public void selectAll() throws Exception {
        List<Student> students = studentService.selectAll();
        for (Student student : students) {
            System.out.println(student);
        }
    }//注解-查所有
    @org.junit.Test
    public void  insert() throws Exception{
        Integer i = studentService.insert(new Student(3, "形参", 18, new Date()));
        System.out.println(i);
    }//注解-新增
    @org.junit.Test
    public void selectById() throws Exception{
        Student student = studentService.selectById(2);
        System.out.println(student);
    }//注解-根据id查
    @org.junit.Test
    public void update() throws Exception{
        Student student = new Student(2,"宣传册",99,new Date());
        Integer update = studentService.update(student);
        System.out.println(update);
    }//注解-修改
@org.junit.Test
    public void  delete() throws Exception{
        Integer delete = studentService.delete(3);
        System.out.println(delete);
    }//注解-删除
@org.junit.Test
    public void selectAll_OnetoOne() throws IOException {
    ArrayList<Stucord> stucords = double_service.selectAll();
    for (Stucord stucord : stucords) {
       System.out.println(stucord.getId()+","+stucord.getCord());
        Person person = stucord.getPerson();
        System.out.println(person);
    }
}//注解一对一--查询
@org.junit.Test
    public void selectAll_OnetoMany() throws Exception{
        List<Clases> clases = clasestoStudent_service.selectAll();
    for (Clases clase : clases) {
        System.out.println(clase);
    }
    }//注解一对多--查询
@org.junit.Test
    public void selecatAll_ManytoMany() throws Exception{
        TeachertoStudent_Service teachertoStudent_service = new TeachertoStudent_Service();
        List<Teacher> teachers = teachertoStudent_service.selectAll();
        for (Teacher teacher : teachers) {
            System.out.println(teacher);
        }
    }//注解多对多--查询--需要数据库中间表(不需要对应的中间类)

}

